package com.word.util;

import cn.hutool.core.util.RandomUtil;

import java.util.Random;

public class RandomIdUtil {

    /**
     * 生成随机id
     * @return id
     */
    public static Long createRandomId() {
        long dateNow = System.currentTimeMillis();
        long randomNum = RandomUtil.randomLong(0, 999);
        return dateNow * 1000 + randomNum;
    }

    /**
     * 生成随机字符串
     * @return 随机密码
     */
    public static String generateRandomString(int length) {
        String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()";
        Random random = new Random();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; ++i) {
            int index = random.nextInt(characters.length());
            char randomChar = characters.charAt(index);
            sb.append(randomChar);
        }
        return sb.toString();
    }
}
